package com.kingland.wanxindong.config;

import org.flywaydb.core.Flyway;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * configuration for enable mybatis framework
 *
 * @author ksc
 */
@Configuration
@MapperScan("resources/com/kingland/wanxindong/mapper")

public class MybatisConfig {
    @Bean
    CommandLineRunner flyway(DataSource dataSource) {
        return new CommandLineRunner() {
            @Override
            public void run(String... args) throws Exception {
                Flyway flyway = Flyway.configure()
                        .schemas("user_access")
                        .dataSource(dataSource).load();
                flyway.migrate();
            }
        };
    }
}
